const Sequelize = require('sequelize')
module.exports = (sequelize, DataTypes) => {
  return AclRole.init(sequelize, DataTypes)
}

class AclRole extends Sequelize.Model {
  static init(sequelize, DataTypes) {
    super.init(
      {
        id: {
          autoIncrement: true,
          type: DataTypes.INTEGER,
          allowNull: false,
          primaryKey: true,
        },
        name: {
          type: DataTypes.STRING(30),
          allowNull: false,
          comment: '角色名称',
        },
        description: {
          type: DataTypes.STRING(50),
          allowNull: false,
          defaultValue: '',
          comment: '角色描述',
        },
        status: {
          type: DataTypes.TINYINT,
          allowNull: false,
          defaultValue: 1,
          comment: '状态：1有效；0禁用',
        },
        createTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '创建时间',
          field: 'create_time',
        },
        updateTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '更新时间',
          field: 'update_time',
        },
        deleteTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '删除时间',
          field: 'delete_time',
        },
      },
      {
        sequelize,
        tableName: 'acl_role',
        timestamps: true,
        underscored: true,
        paranoid: true,
        createdAt: 'createTime',
        updatedAt: 'updateTime',
        deletedAt: 'deleteTime',
        indexes: [
          {
            name: 'PRIMARY',
            unique: true,
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'name',
            using: 'BTREE',
            fields: [{ name: 'name' }],
          },
        ],
      },
    )
    return AclRole
  }
}
